AC_INIT(LibBancoODBC, 1.0.0, alcione.sombra@gmail.com, libbancoodbc, http://www.alcionesytes.net)
AC_PREREQ([2.50])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([1.11 gnu -Wall dist-xz])
AC_CONFIG_MACRO_DIR([m4])
m4_pushdef([AC_INCLUDES_DEFAULT], [$1])
AC_COPYRIGHT([Alcione Ferreira])
AC_REVISION([$Revision: 1.0.0 $])

AC_CONFIG_HEADERS([src/configbodbc.h])
LT_INIT([static])
AC_PROG_CXX
AC_PROG_LD
AC_LANG([C++])

######################################################################
# DOXYGEN SUPPORT
######################################################################

DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_MAN_FEATURE(ON)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(ON)
DX_PS_FEATURE(ON)

DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg],[doc])

######################################################################

AM_PROG_LIBTOOL
AC_PREFIX_DEFAULT([/usr])
AC_CANONICAL_HOST
AC_MSG_NOTICE([Plataforma: $host_os])
case "$host_os" in
	linux*)
		OS_HOST="yes";
		;;
	mingw*)
		OS_HOST="no";
		;;
esac;

if test x"$OS_HOST" = xyes; then
	# --with-dinamico
	AC_ARG_WITH(dinamico,
	  [AS_HELP_STRING([--with-dinamico],[Compilação Dinâmica])
	  ],
	  [ ],
	  [with_dinamico=yes]
	)
	AC_ARG_WITH(odbc_config, [	--with-odbc_config=DIR	odbc_config for UnixODBC],
	[
	if test "$withval" != no
	then
		ODBC_CONFIG="$withval"
		if test ! -f "${ODBC_CONFIG}"
		then
			AC_MSG_ERROR([Could not find your UnixODBC installation])
		fi
	fi
	],
	[
	STANDARD_PREFIXES="/usr /usr/local /opt /local /mingw"
	ODBC_CONFIG=""
	for i in `echo "$STANDARD_PREFIXES"`; do
		if test -f "$i/bin/odbc_config"; then
			ODBC_CONFIG="$i/bin/odbc_config"
			break;
		fi
	done
	])

	if test x"$ODBC_CONFIG" = x; then
		AC_MSG_ERROR([$PACKAGE requires odbc_config])
	fi
	AC_SUBST([ODBC_LIBS],  [`$ODBC_CONFIG --libs`])
	AC_SUBST([ODBC_INCLUDE], [`$ODBC_CONFIG --include-prefix`])
	AC_SUBST([ODBC_CPPFLAGS],  [`$ODBC_CONFIG --cflags`])
	AC_SUBST([ODBC_LDFLAGS], [`$ODBC_CONFIG --libs`])
	AC_MSG_CHECKING([UnixODBC: Identificando modo de compilação: ])
	if test "x$with_dinamico" = "xyes"; then
		AC_SUBST([LIBODBC_libs],['$(ODBC_LIBS)'])
		AC_MSG_RESULT([Dinâmica])
		break;
	else
		AC_SUBST([LIBODBC_libs],[`$ODBC_CONFIG --static-libs`])
		AC_MSG_RESULT([Estática])
	fi
else
	AC_SUBST([ODBC_LIBS],  ['-lws2_32 -lodbc32'])
	AC_SUBST([ODBC_INCLUDE], [''])
	AC_SUBST([ODBC_CPPFLAGS],  ['-D_WIN32_WINNT=0x0501'])
	AC_SUBST([ODBC_LDFLAGS], ['$(ODBC_CPPFLAGS) $(ODBC_LIBS)'])
	AC_SUBST([LIBODBC_libs],['$(ODBC_LIBS)'])
fi

AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

AC_CHECK_HEADERS([iostream string string.h fstream vector],,,[AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([ctime cstdio cstdlib ctype.h ltdl.h dlfcn.h],,,[AC_INCLUDES_DEFAULT])
AC_SEARCH_LIBS([lt_dlopen], [ltdl])
AC_SEARCH_LIBS([dlopen], [dl])

AC_SUBST([LIBBANCOODBC_SO_VERSION], [1:0:0])
AC_SUBST([LIBBANCOODBC_API_VERSION], [1.0])

#AC_DEFINE([DB_TESTE],["../teste/db.conf"],[Arquivo de Configuração Teste])
AH_TOP([
#ifndef __CONFIGBODBC_H__
#define __CONFIGBODBC_H__ 1

#if  defined(__WIN32__) || defined(__WIN__)
#define NO_LINUX 1
#include <windows.h>
#endif
])
AH_BOTTOM([
#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#ifdef HAVE_STRING
# include <string>
#endif
#ifdef HAVE_FSTREAM
# include <fstream>
#endif
#ifdef HAVE_VECTOR
# include <vector>
#endif
#ifdef HAVE_CTIME
# include <ctime>
#endif
#ifdef HAVE_CSTDIO
# include <cstdio>
#endif
#ifdef HAVE_CSTDLIB
# include <cstdlib>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifdef HAVE_LTDL_H
# include <ltdl.h>
#endif
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_HPDF_H
# include <hpdf.h>
#endif
#ifdef HAVE_ZLIB_H
# include <zlib.h>
#endif

#ifndef HAVE_UNISTD_H
 #define HAVE_UNISTD_H
#endif
#ifndef HAVE_PWD_H
 #define HAVE_PWD_H
#endif
#ifndef HAVE_SYS_TYPES_H
 #define HAVE_SYS_TYPES_H
#endif
#ifndef HAVE_LONG_LONG
 #define HAVE_LONG_LONG
#endif
#ifndef ODBCINT64
 #define ODBCINT64 long
#endif
#ifndef UODBCINT64
 #define UODBCINT64 unsigned long
#endif
#ifndef SIZEOF_LONG_INT
 #define SIZEOF_LONG_INT 8
#endif

#endif /*__CONFIGBODBC_H__*/
])

AC_CONFIG_FILES([Makefile src/Makefile teste/Makefile libbancoodbc-${LIBBANCOODBC_API_VERSION}.pc:libbancoodbc.pc.in])
AC_OUTPUT
